package com.zjdiepu.www.task.file;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.zjdiepu.www.ibiz.base.IOtherAttachmentsService;
import com.zjdiepu.www.ibiz.other.IOtherMediaFailService;
import com.zjdiepu.www.model.other.dto.OtherMediaFail;
import com.zjdiepu.www.model.other.ext.OtherMediaFailExt;
/**
 * 项目名称：dpqc-parent-manager-schedule <br/> 
 * 类名称：FileHanlerTask <br/>  
 * 类描述：文件处理任务 <br/>    
 * 创建人：xiongxiaotun <br/> 
 * 创建时间：2017年4月21日 下午2:09:10  <br/>   
 * 修改人：xiongxiaotun <br/> 
 * 修改时间：2017年4月21日 下午2:09:10   <br/>  
 * 修改备注：    <br/> 
 * @version V1.0   <br/>
 */
@Component
public class FileHanlerTask {
	private Logger logger = LoggerFactory.getLogger(getClass());
	
	@Autowired
	private IOtherAttachmentsService otherAttachmentsService;
	
	@Autowired
	private IOtherMediaFailService otherMediaFailService;

	/**
	 * @author xiongxiaotun <br/>
	 * @Title: execute  <br/>
	 * @Description: 多媒体文件处理 <br/>
	 * @version V1.0  <br/>
	 */
	@Scheduled(cron="${schedule.media.handler.cron}")
	public void execute() {
		logger.debug("media handler start.");
		OtherMediaFailExt otherMediaFailExt = new OtherMediaFailExt();
		
		boolean continueHandle = true;
		int page = 0;
		final int row = 50;
		otherMediaFailExt.setRows(row);
		while(continueHandle){
			otherMediaFailExt.setPage(++page); //从第一页开始
			List<OtherMediaFail> otherMediaFails = otherMediaFailService.selectByExt(otherMediaFailExt);
			for(OtherMediaFail otherMediaFail : otherMediaFails) {
				try{
					otherAttachmentsService.saveProcessedMediaFile(otherMediaFail);
				}catch(Exception e) {
					continue;
				}
			}
			continueHandle = (otherMediaFails.size() == row);
		}
		logger.debug("media handler end.");
	}
	
}
